package com.cqjtu.education.controller;

import com.cqjtu.education.entity.Section;
import com.cqjtu.education.service.SectionService;
import com.github.pagehelper.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Section)表控制层
 *
 * @author makejava
 * @since 2022-04-20 15:49:08
 */
@RestController
@RequestMapping("section")
public class SectionController {
    /**
     * 服务对象
     */
    @Resource
    private SectionService sectionService;


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Section> queryById(@PathVariable("id") String id) {
        return ResponseEntity.ok(this.sectionService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param section 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Section> add(Section section) {
        return ResponseEntity.ok(this.sectionService.insert(section));
    }

    /**
     * 编辑数据
     *
     * @param section 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Section> edit(Section section) {
        return ResponseEntity.ok(this.sectionService.update(section));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(String id) {
        return ResponseEntity.ok(this.sectionService.deleteById(id));
    }

}

